﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SOM.AbstractDALFactory;
using SOM.Common;
using SOM.ConcreteDAL;
using SOM.ConcreteDALFactory;
using SOM.Model;
using SOM.Security;
using System.Web.Security;
using System.Configuration;

public partial class MasterPage : System.Web.UI.MasterPage
{
    private string Saudacao
    {
        get
        {
            if (Session["Usuario"] != null)
            {
                SOMAbstractDALFactory factory = new SOMConcreteDALFactory();
                UsuarioDAL usuarioDAL = factory.CreateUsuarioDAL();
                Usuario usuario = usuarioDAL.FindByNickname(Session["Usuario"].ToString());

                if (usuario != null)
                    return "Seja bem vindo " + usuario.usr_nm_usuario + ".";
                else
                    return "Seja bem vindo anonimo";

            }
            else
            {
                return string.Empty;
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Page.Title = ConfigurationManager.AppSettings["SOM.ApplicationName"];
        lblSaudacao.Text = Saudacao;

        if (Session["Usuario"] == null)
        {
            this.lkbSair.Visible = false;
            this.lkbLogin.Visible = true;

        }
        else
        {

            this.lkbSair.Visible = true;
            this.lkbLogin.Visible = false;
        }

    }
    protected void lkbSair_Click(object sender, EventArgs e)
    {
        Session.Clear();
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
    }

    protected void lkbLogin_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Login.aspx");
    }
    
}
